package cl.ufro.conexion;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

public class ConexionWS {
	
	
	private static String METHOD_NAME ;
	private static String NAMESPACE ;
	private static String URL;




	public String getcoordenadas(String latitud, String longitud,String radio){

		NAMESPACE = "http://ws"; 
		URL = "http://200.13.4.219:8080/SOAOpensystemDOS/services/Establecimiento";
		METHOD_NAME = "getColegioCoordenadasPorRadios";

		String SOAP_ACTION = NAMESPACE + METHOD_NAME;
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

		PropertyInfo latituduser = new PropertyInfo();
		PropertyInfo longituduser = new PropertyInfo();
		PropertyInfo radiouser = new PropertyInfo();
		
		latituduser.setName("latitud");
		latituduser.setValue(latitud);
		latituduser.setType(String.class);

		longituduser.setName("longitud");
		longituduser.setValue(longitud);
		longituduser.setType(String.class);
		
		radiouser.setName("radioParametro");
		radiouser.setValue(radio);
		radiouser.setType(String.class);

		request.addProperty(latituduser);
		request.addProperty(longituduser);
		request.addProperty(radiouser);
		
		SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		soapEnvelope.dotNet = true;
		soapEnvelope.implicitTypes =true;
		soapEnvelope.setOutputSoapObject(request);

		AndroidHttpTransport aht = new AndroidHttpTransport(URL);

		String datosJsonString;
		try
		{ //realiza la llamada
			aht.call(SOAP_ACTION, soapEnvelope);
			SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
			datosJsonString =resultString.toString();
			return datosJsonString;
		}
		catch (Exception e)
		{
			e.printStackTrace();
			// en caso de no tener acceso al web service
			datosJsonString = "Error Conexion";}
		return datosJsonString;
	}

}
